<template>
    <div class="wrapper" v-if="type != ''">
        <!--    <div class="way">-->
        <!--      Home <span>></span> <span class="currentTab">{{ type }}</span>-->
        <!--    </div>-->
        <!-- <ArticleViewHeadContent></ArticleViewHeadContent> -->
        <ArticleViewContent v-if="pageContent" :data="pageContent" :time="time"></ArticleViewContent>
        <ArticleViewRecommendedNews
                v-if="recommendedNewsShow"
                :data="pageContent.ref_article"
        ></ArticleViewRecommendedNews>
        <ArticleViewPressContacts v-if="pressContactVisible"
                                  :data="pageContent.pressContact"></ArticleViewPressContacts>
    </div>
</template>

<script setup lang="ts">
    import {ref, reactive} from 'vue'

    const config = useRuntimeConfig();
    const apiURL = config.public.apiURL;

    let searchText = ref('')
    const route = useRoute()

    useHead({
        title: 'Exeed Newsroom',//网站标题
        link: [//网站link，可以在这里引入css和icon等
            {rel: 'shortcut icon', href: '/images/favicon.ico'},
            {rel: 'apple-touch-icon', href: '/images/favicon.ico'}
        ]
    })

    // 当访问/posts/1时，route.params.id将为1

    const token = route.query.token;
    const {data: content} = token ? await useFetch(`/api/page/getSketchById?id=${route.params.id}&token=${token}`) : await useFetch(`/api/page/getPageById?id=${route.params.id}`);


    const title = ref(undefined);
    const type = ref(undefined)
    const time = ref(new Date().getTime())

    const pageContent = ref(undefined);

    if (content.value) {
        title.value = content.value.data.title;

        if (content.value.data.pageContent) {
            type.value = content.value.data.pageContent.type;
            pageContent.value = content.value.data.pageContent;
        }
        if (content.value.data.publishTime && content.value.data.publishTime > 0) {
            time.value = content.value.data.publishTime;
        }

        // console.log(pageContent.value)
    }

    const recommendedNewsShow = ref(false)
    if (pageContent.value && pageContent.value.ref_article.length > 0) {
        recommendedNewsShow.value = true;
    }

    const pressContactVisible = ref(false);

    if (pageContent.value && pageContent.value.pressContact) {
        pressContactVisible.value = true;
    }
</script>

<style scoped lang="scss">
    .wrapper {
        background-color: #ffffff;
        width: 1920px;

        .way {
            width: 1600px;
            height: 60px;
            padding: 0px 90px;
            padding-top: 20px;
            vertical-align: middle;
            font-size: 16px;

            .currentTab {
                font-size: 16px;
                font-weight: 400;
                color: #c78e66;
            }
        }
    }
</style>
